package column


import (
	"github.com/treelab/updatecolumn/models"
)

  func instanceType() int32 {
    return models.Currency
  }

  deleteColumnEdges(command: UpdateColumn_v2, o: CommonOptions) {
    const { column } = command;
    o.delQuads.push(...this.dgraphHelperService.getRemoveEdgeQuads(column.uid!, ['currencyFormat']));
    super.deleteColumnEdges(command, o);
    return this;
  }

  public hasNothingToUpdate(command: UpdateColumn_v2) {
    const { column } = command;
    const currencyColumnConfig = command.columnConfig as CurrencyColumnConfig;
    return (
      column.columnType === this.instanceType &&
      column.currencyFormat === currencyColumnConfig.currencyFormat &&
      column.defaultNumber === currencyColumnConfig.defaultNumber &&
      column.precision === currencyColumnConfig.precision
    );
  }

  async updateColumn(
    command: UpdateColumn_v2,
    o: CommonOptions,
    helper: { rows?: Row[]; columnCopy?: Column; referenceColumns?: Column[]; userGroup?: any },
  ) {
    await super.updateColumn(command, o, helper);

    const { column, columnConfig } = command;
    const { currencyFormat } = columnConfig as CurrencyColumnConfig;
    column.currencyFormat = currencyFormat;
    return this;
  }

  async convertColumn(
    command: UpdateColumn_v2,
    o: CommonOptions,
    helper: { rows?: Row[]; columnCopy?: Column; referenceColumns?: Column[]; userGroup?: any },
  ) {
    const { column } = command;
    const currencyColumnConfig = command.columnConfig as CurrencyColumnConfig;
    if (
      column.currencyFormat === currencyColumnConfig.currencyFormat &&
      column.precision === currencyColumnConfig.precision &&
      column.defaultNumber === currencyColumnConfig.defaultNumber
    ) {
      return this;
    }
    await super.convertColumn(command, o, helper);
    return this;
  }

